package com.njitzx.fileupload.enu;

import java.util.Arrays;
import java.util.List;

public enum FileCategory {
    IMAGE(Arrays.asList(".jpg", ".jpeg", ".png", ".gif"), "image/"),
    DOCUMENT(Arrays.asList(".doc", ".xls", ".ppt", ".txt", ".pdf", ".mp3", ".wav", ".ply"), "file/"),
    VIDEO(Arrays.asList(".mp4", ".avi", ".mov"), "video/"),
    AUDIO(Arrays.asList(".mp3", ".wav"), "audio/");

    private List<String> extensions;  // 支持的文件扩展名
    private String bucketPrefix;      // 存储路径前缀

    // 构造函数
    FileCategory(List<String> extensions, String bucketPrefix) {
        this.extensions = extensions;
        this.bucketPrefix = bucketPrefix;
    }

    // 获取支持的文件扩展名列表
    public List<String> getExtensions() {
        return extensions;
    }

    // 获取对应的存储路径
    public String getBucketPrefix() {
        return bucketPrefix;
    }

    // 根据文件扩展名获取对应的存储路径
    public static String getBucketPrefixByExtension(String fileSuffix) {
        for (FileCategory category : FileCategory.values()) {
            if (category.getExtensions().contains(fileSuffix)) {
                return category.getBucketPrefix();
            }
        }
        return null;  // 如果没有找到对应的类型，返回 null
    }
}
